package view;

import java.util.HashMap;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
public class LanguageLoader {
    public static void loadUserLanguage (HttpServletRequest request, HttpServletResponse response, Action me){
        
        ServletContext application = me.getServlet().getServletConfig().getServletContext();
        String userLang = request.getParameter("lang");
        String langs [] = (String[])application.getAttribute("lang");
        int i = 0;
        for (; i <langs.length;i++){
            if (langs[i].equalsIgnoreCase(userLang))
                break;
        }
        HashMap<String,String> LanguageHashMaps[] = (HashMap<String,String>[])application.getAttribute("langConfig");
        HashMap<String,String> userHashMap = (HashMap<String,String>)LanguageHashMaps[i].clone();
        if (userHashMap == null){
                System.out.println("user hash map is null");
        }
        request.getSession().setAttribute("lang",userHashMap);
        System.out.println("Language Loaded!");
        Runtime.getRuntime().gc();
    }
    
    
}
